﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SpringDynamicExpressonResolver.cs" company="Collaboris Ltd.">
//   Copyright (c) Collaboris Ltd. All rights Reserved.
// </copyright>
// <summary>
//   Defines the SpringDynamicExpressonResolver type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Collaboris.Saf.Engine.Factory.Spring
{
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.Specialized;

    using global::Spring.Collections;
    using global::Spring.Expressions;
    using global::Spring.Objects.Factory.Config;

    public class SpringDynamicExpressonResolver : IStringExpressionResolver
    {
        #region Fields

        private string placeholderPrefix;
        private string placeholderSuffix;

        #endregion

        #region Constructors

        public SpringDynamicExpressonResolver(string placeholderPrefix, string placeholderSuffix)
        {
            this.placeholderPrefix = placeholderPrefix;
            this.placeholderSuffix = placeholderSuffix;
        }

        #endregion

        public object ResolveExpression(string propertyExpression, NameValueCollection variables)
        {
            string variableValue;
            
            PropertyPlaceholderConfigurer placeholderConfigurer = new PropertyPlaceholderConfigurer();
            placeholderConfigurer.PlaceholderPrefix = this.placeholderPrefix;
            placeholderConfigurer.PlaceholderSuffix = this.placeholderSuffix;
            variableValue = placeholderConfigurer.ParseString(variables, propertyExpression, new HashedSet());
            
            return variableValue;
        }
    }
}
